from apps.common.base.dao import BaseDao
from apps.merchant.item.serializers import *
from django.db.models import F

class ItemDao(BaseDao):
    MODEL_CLASS = Item
    SERI_CLASS = ItemBaseSerializer


    # 增加销量
    def addSales(self, itemId, n):
        item = ItemDao().findOneByObjId(itemId)
        item.sales = F('sales') + n
        item.save()

    # 减少销量
    def subSales(self, itemId, n):
        item = ItemDao().findOneByObjId(itemId)
        item.sales = F('sales') - n
        item.save()